import { plugin, getEnvConfig } from './config';
import { defineConfig } from 'vite';
//配置vue项目
import Vue from '@vitejs/plugin-vue';
export default defineConfig({
  plugins: [Vue(), plugin.autoImportPlugin()],
  server: {
    port: 8848,
    host: '0.0.0.0',
  },
  resolve: {
    alias: {
      '@': '/src',
    },
  },
  //全局注入scss变量
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/style/index.scss" as *;`,
      },
    },
  },
  //打包分片 代码分割
  build: {
    rollupOptions: {
      output: {
        //如果是图片 放到 assets/images 文件夹下
        chunkFileNames: 'assets/js/[name]-[hash].js',
        entryFileNames: 'assets/js/[name]-[hash].js',
        assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
        manualChunks: (id) => {
          if (id.includes('node_modules/ant-design')) {
            return 'antd';
          }
          if (id.includes('vue')) {
            return 'vue';
          }
          if (id.includes('node_modules')) {
            return 'vendors';
          }
          if (id.includes('src/components')) {
            return 'components';
          }
        },
      },
    },
  },
});
